package com.example.sty.controller;

import com.example.sty.domain.UserProject;
import com.example.sty.domain.UserProjectVO;
import com.example.sty.service.ProjectService;
import com.example.sty.service.UserService;
import com.example.sty.domain.Project;
import com.example.sty.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class MainController {

    @Autowired
    private UserService userService;
    @Autowired
    private ProjectService projectService;



    /**
     * 登录
     *
     * @param username
     * @param password
     * @return
     */
    @GetMapping("/login")
    public User login(@RequestParam String username, @RequestParam String password){
        return userService.login(username, password);
    }

    /**
     * 注册
     *
     * @param username
     * @param password
     * @param roleId
     */
    @GetMapping("/register")
     public boolean register(@RequestParam String username, @RequestParam String password, @RequestParam String roleId){
         userService.register(username, password, roleId);
         return true;
     }

    /**
     * 发布运动项目
     *
     * @param project
     */
    @PostMapping("/insertProject")
    public void insertProject(@RequestBody Project project){
        projectService.insertProject(project);
    }

    /**
     * 奖项颁布
     *
     * @param userProject
     */
    @PostMapping("/award")
    public Boolean insertUserProject(@RequestBody UserProject userProject){
        projectService.insertUserProject(userProject);
        return true;
    }

    /**
     * 裁判打分
     *
     * @param userProject
     */
    @PostMapping("/score")
    public Boolean insertScore(@RequestBody UserProject userProject){
        projectService.insertUserProject(userProject);
        return true;
    }
    /**
     * 查询所有的运动项目
     *
     * @return
     */
    @GetMapping("/getProjects")
    public List<Project> getProjects(){
        return projectService.getProjects();
    }

    /**
     * 查看单个项目的报名人信息
     *
     * @return
     */
    @GetMapping("/getUserProjects")
    List<UserProjectVO> getUserProjects(Integer projectId){
        return projectService.getUserProjects(projectId);
    }

    /**
     * 查询受伤人员
     *
     * @return
     */
    @GetMapping("/getIsInjured")
    List<User> getIsInjured(){
        return projectService.getIsInjured();
    }
    
    @GetMapping("/getAllUserProjects")
    public List<UserProjectVO> getAllUserProjects(){
        return projectService.getAllUserProjects();
    }
}
